package idv.ccApp.cwFileExplore;

import android.graphics.Bitmap;
import android.os.AsyncTask;
import idv.ccApp.cwFileExplore.MuPDFInt.MuPDFCore;

/**
 * Created with IntelliJ IDEA.
 * User: cc.cheng
 * Date: 2013/8/20
 * Time: 上午 10:06
 * To change this template use File | Settings | File Templates.
 */
public class PdfDrawPageAsyncTask extends AsyncTask <PageDrawingInfo, Integer, Object>  {
  private OnTaskCompleted mTaskCompleteCB;
  private MuPDFCore mPdfCore;
  private Bitmap mNewlyBitmap;
  public PdfDrawPageAsyncTask( OnTaskCompleted cb, MuPDFCore core) {
    super();
    this.mTaskCompleteCB = cb;
    this.mPdfCore = core;
  }

  @Override
  protected Object doInBackground(PageDrawingInfo... obj) {
    mNewlyBitmap = this.mPdfCore.drawPage(
        obj[0].mPage,
        obj[0].mWidth,
        obj[0].mHeight,
        obj[0].mPatchX,
        obj[0].mPatchY,
        obj[0].mPatchW,
        obj[0].mPatchH
    );
    return obj;
  }

  @Override
  protected void onCancelled() {
    super.onCancelled();
  }

  @Override
  protected void onCancelled(Object o) {
    super.onCancelled(o);
  }

  @Override
  protected void onPostExecute(Object o) {
    //super.onPostExecute(o);
    //if(this.mNewlyBitmap!=null)
      this.mTaskCompleteCB.onTaskCompleted(this.mNewlyBitmap);
    //this.mNewlyBitmap = null;
  }

  @Override
  protected void onPreExecute() {
    super.onPreExecute();
  }

  @Override
  protected void onProgressUpdate(Integer... values) {
    super.onProgressUpdate(values);
  }
}
